﻿using QDChat.Domain;
using QDChat.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QDChat.Data
{
    public class DbUser : IChatUser
    {
        private static string TableName = "chat_user";

        public int Insert(User model)
        {
            using (var db = new QDMallDatabase())
            {
                db.Insert(model);
            }
            return model.Id;
        }

        public int Update(User model)
        {
            using (var db = new QDMallDatabase())
            {
                return db.Update(model);
            }
        }

        public User Get(int id)
        {
            using (var db = new QDMallDatabase())
            {
                return db.SingleOrDefault<User>($"select top 1 * from {TableName} where id={id}");
            }
        }

        public User GetByOpenId(string openId)
        {
            using (var db = new QDMallDatabase())
            {
                return db.SingleOrDefault<User>($"select top 1 * from {TableName} where openId=@0", openId);
            }
        }
    }
}
